package _02UDP通信;

import java.io.IOException;
import java.net.*;

public class UDPSender {
    public static void main(String[] args) throws IOException {

            //1.创建发送端   new DatagramSocket()
            DatagramSocket socket = new DatagramSocket();

            //2.创建数据包，并指定IP和端口
            byte[] bytes = "你好,世界".getBytes();//数据包
            InetAddress ip = InetAddress.getByName("127.0.0.1");
            DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length,ip,9999);
            //3. 发送数据。send(DatagramPacket packet)
            socket.send(packet);
            //4.关闭资源
            socket.close();


    }
}
